<?php
class BbsMembers extends CActiveRecord {
	const GENDER_MALE = 1;
	const GENDER_FEMALE = 2;
	const GENDER_UNSET = 0;
	
	public static function model($className = __CLASS__) {
		return parent::model($className);
	}

	public function rules() {
		return array(
			array('gender', 'in', 'range' => array(self::GENDER_UNSET, self::GENDER_MALE, self::GENDER_FEMALE), 'message' => '请选择有效的性别。'),
			array('bday', 'match', 'pattern' => '/^[0-9]{4}\-[0-9]{1,2}-[0-9]{1,2}$/', 'message' => '请填写正确的生日日期'),
		);
	}

//	public function relations() {
//		return array(
//		);
//	}

	public function tableName() {
		return 'xinli_members';
	}

	static public function gender2Text() {
		return array(
			self::GENDER_MALE => '男',
			self::GENDER_FEMALE => '女',
			self::GENDER_UNSET => ''
		);
	}

	public function getGenderText() {
		$genders = self::gender2Text();
		return isset($genders[$this->gender]) ? $genders[$this->gender] : '未知 #'.$this->gender;
	}
}